<template>
  <div>
    <el-pagination
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="pageSizes"
      :background="background"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script setup lang="ts">
import { PropType } from 'vue'
// import type { ComponentSize } from 'element-plus'
// const currentPage4 = ref(4)
// const pageSize4 = ref(100)
// const size = ref<ComponentSize>('default')
// const background = ref(false)
// const disabled = ref(false)

// const handleSizeChange = (val: number) => {
//   console.log(`${val} items per page`)
// }
// const handleCurrentChange = (val: number) => {
//   console.log(`current page: ${val}`)
// }
const props = defineProps({
  total: {
    required: true, //该属性是否是必需的
    type: Number as PropType<number>, //类型
    default: 0 //该属性的默认值
  },
  page: {
    type: Number,
    default: 1
  },
  limit: {
    type: Number,
    default: 20
  },
  pageSizes: {
    type: Array as PropType<number[]>,
    default() {
      return [10, 20, 30, 50]
    }
  },
  layout: {
    type: String,
    default: 'total, sizes, prev, pager, next, jumper'
  },
  background: {
    type: Boolean,
    default: true
  },
  autoScroll: {
    type: Boolean,
    default: true
  },
  hidden: {
    type: Boolean,
    default: false
  }
})

const emit = defineEmits(['pagination', 'update:page', 'update:limit'])

const currentPage = useVModel(props, 'page', emit)
const pageSize = useVModel(props, 'limit', emit)

const handleSizeChange = (val: number) => {
  emit('pagination', { page: currentPage, limit: val })
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  emit('pagination', { page: val, limit: props.limit })
}
</script>

<style scoped>
.demo-pagination-block + .demo-pagination-block {
  margin-top: 10px;
}
.demo-pagination-block .demonstration {
  margin-bottom: 16px;
}
</style>